import { reactive, toRefs } from 'vue'
import { defineStore } from 'pinia'

// 方法一
export const useGlobalStore = defineStore('counter', () => {
    const state = reactive({
        loading: 0,
    })
    // 加减loading
    const countLoading = (val:number) => {
        state.loading += val
        if (state.loading < 0) state.loading = 0
    }
    // 设定loading值
    const setLoading = (val:number) => {
        state.loading = val
    }
    // 清除loading
    const clearLoading = () => {
        state.loading = 0
    }
    return {
        ...toRefs(state),
        countLoading,
        setLoading,
        clearLoading,
    }
})
// 方法二
// export const useCounterStore = defineStore('counter', {
//     state: () => ({
//         count: 0,
//     }),
//     actions: {
//         increment() {
//             this.count++
//         },
//     },
// })
